//
//  WBFooterView.swift
//  WeiBo
//
//  Created by chenguanglei on 16/11/29.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class WBFooterView: UIView {

    
    var footerViewModel: WBHomeViewModel?{
        
        didSet{
            
          
            commentButton.setTitle(footerViewModel?.comments_count, for: UIControlState.normal)
            
            retweetButton.setTitle(footerViewModel?.reposts_string, for: UIControlState.normal)
            
            goodButton.setTitle(footerViewModel?.attitudes_count, for: UIControlState.normal)
            
        }
        
    }
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        
        super.init(coder: aDecoder)
        
    }
    
    
    private func setupUI(){
        
        backgroundColor = UIColor.white
        
        addSubview(retweetButton)
        addSubview(commentButton)
        addSubview(goodButton)
        
        // 约束
        retweetButton.snp_makeConstraints { (make) in
            
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            // 关键约束
            make.width.equalTo(commentButton.snp_width)
            
        }
        
        commentButton.snp_makeConstraints { (make) in
            
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            
            make.left.equalTo(retweetButton.snp_right)
            make.right.equalTo(goodButton.snp_left)
            
        }
        
        goodButton.snp_makeConstraints { (make) in
            make.top.equalTo(self.snp_top)
            make.right.equalTo(self.snp_right)
            make.bottom.equalTo(self.snp_bottom)
            
            // 关键约束
            make.width.equalTo(commentButton.snp_width)
        }
        
        
        let lineLeft = getLine()
        let lineRigth = getLine()
        
        addSubview(lineLeft)
        addSubview(lineRigth)
        
        //        lineRigth.backgroundColor = UIColor.red
        
        lineLeft.snp_makeConstraints { (make) in
            make.centerY.equalTo(self.snp_centerY)
            make.centerX.equalTo(self.retweetButton.snp_right)
            
            make.height.equalTo(30)
        }
        
        lineRigth.snp_makeConstraints { (make) in
            make.centerY.equalTo(self.snp_centerY)
            make.centerX.equalTo(goodButton.snp_left)
            
            make.height.equalTo(30)
        }

        
    }

    
    
    // 第三步: 懒加载
    private lazy var retweetButton: UIButton = UIButton(titleNormal: "转发", titleColor: UIColor.darkGray, size: 14, bgimageNormal: nil, imageNormal: "timeline_icon_retweet", corner: 0)
    
    private lazy var commentButton: UIButton = UIButton(titleNormal: "评论", titleColor: UIColor.darkGray, size: 14, bgimageNormal: nil, imageNormal: "timeline_icon_comment", corner: 0)
    
    private lazy var goodButton: UIButton = UIButton(titleNormal: "点赞", titleColor: UIColor.darkGray, size: 14, bgimageNormal: nil, imageNormal: "timeline_icon_unlike", corner: 0)
    
    // 返回一条线
    private func getLine() -> UIImageView {
        return UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
    }

    
    
}
